const app = getApp();
Page({
  data: {
    two_2:5, //没有点亮的星星数
    one_2:0, //点亮的星星数
    list: ["极差", "较差", "一般", "不错","很棒"],
    Comment:'',
    textValue:'',
    appointmentId:null,
    orderId:null,
  },
  onLoad:function(option){
    console.log(option,'评价')
    if (option) {
      this.setData({
        appointmentId:option.appointmentId,
        orderId:option.orderId
      })
    }
  },
  clickTap:function(e){
    let in_xin = e.currentTarget.dataset.in, one_2;
    if( in_xin == 'star' ) one_2 = Number(e.currentTarget.id);
    else one_2 = Number(e.currentTarget.id)+this.data.one_2;
    this.setData({ one_2 : one_2, two_2 : 5-one_2, Comment: this.data.list[one_2-1] });
  },
  inputTxt:function(e){
    let value = e.detail.value;
    this.setData({
      textValue:value
    })
  },
  submitEvaluate:function(){
    let _this = this,
        data = this.data;
    if (data.one_2 > 0) {
      app.util.ajax({
        url:'api/Comment/addComment',
        method:'POST',
        data:{
          order_id:data.orderId,
          appointment_id:data.appointmentId,
          attitude_level:data.one_2,
          comment_txt:data.textValue
        }
      },function(data){
        wx.navigateBack({delta:1})
      })
    }else{
      wx.showToast({
        title:"请对服务进行评价",
        icon:'none'
      })
    }
  }
})
